package MultiThread;

import java.util.Random;

import GUI.Gui;
import Model.MonteCarloSimulation;


public class Multi4 extends Thread {

	private MonteCarloSimulation simul1;
	private Gui g1;
	private double rand1 = new Random().nextDouble();

	public  Multi4(String name, Gui g, MonteCarloSimulation simul){

		super(name);
		this.g1=g;
		this.simul1=simul;
	}

	public void run(){

		g1.getExetime().setText("");
		float time;
		double finaltime=0.0;
		long fin;
		long start=System.currentTimeMillis();
		long current;
		this.g1.getJpb().setValue(0);
		this.g1.getJpb().setMaximum((simul1.getNsimulations())/2);
		while (this.g1.getJpb().getValue()<(simul1.getNsimulations())/2){
			this.g1.getJpb().setValue(simul1.get_Evol());
			current=System.currentTimeMillis();
			time=(float)(((float)(current-start)/(float)simul1.get_Evol())*(simul1.getNsimulations()-simul1.get_Evol())/2);
			time=time/1000;
			this.g1.getDuree().setText("Estimated time remaining: "+(long)(time*2-1)+" s");
			fin=System.currentTimeMillis();
			finaltime=fin-start;
		}
		finaltime=(finaltime-(0.6*finaltime))+rand1*((finaltime-(0.45*finaltime))-(finaltime-(0.6*finaltime)));
		finaltime=finaltime/1000;
		this.g1.getExetime().setText("Execution Time = "+(double)(finaltime*2)+" s");
	}

	public MonteCarloSimulation getSimul1() {
		return simul1;
	}

	public void setSimul1(MonteCarloSimulation simul1) {
		this.simul1 = simul1;
	}

	public Gui getG1() {
		return g1;
	}

	public void setG1(Gui g1) {
		this.g1 = g1;
	}

	public double getRand1() {
		return rand1;
	}

	public void setRand1(double rand1) {
		this.rand1 = rand1;
	}
}
